{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "73bd968b-d970-4a05-94ef-4e7abf990827",
   "metadata": {},
   "source": [
    "Chapter 14\n",
    "\n",
    "# 数列求和\n",
    "Book_3《数学要素》 | 鸢尾花书：从加减乘除到机器学习 (第二版)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96155253-921c-4010-8429-abcf74c00d97",
   "metadata": {},
   "source": [
    "这段代码的主要目的是使用符号计算和数值计算来研究某些数列的部分和以及它们在 $n \\to \\infty$ 时的极限行为。代码分为三个部分：定义数列的部分和、计算极限值、绘制部分和的收敛趋势图。\n",
    "\n",
    "1. **定义数列的部分和**：代码使用`SymPy`库的`Sum`函数定义了三种数列的部分和表示法。数列的形式分别为：\n",
    "   - $$ S_n = \\sum_{k=0}^{n} \\frac{1}{2^k} $$\n",
    "   - $$ S_n = \\sum_{k=0}^{n} \\frac{1}{(k+1)(k+2)} $$\n",
    "   - $$ S_n = \\sum_{k=0}^{n} \\frac{1}{k!} $$\n",
    "\n",
    "   其中，$n$表示累加的上限。每种数列的表达式对应着不同的收敛特性。例如，$\\sum \\frac{1}{2^k}$ 是一个以 $2$ 为底的几何级数，通常是收敛的。\n",
    "\n",
    "2. **计算数列极限**：使用`limit_seq`函数计算数列在 $n \\to \\infty$ 时的极限值，即部分和是否存在一个收敛的终值。例如，对于 $\\sum \\frac{1}{k!}$，代码会计算其在无穷远处的收敛值，因为阶乘的快速增长导致此数列快速收敛。\n",
    "\n",
    "3. **数值化并计算部分和**：代码通过`lambdify`将符号表达式转换为可数值化的Python函数`seq_sum_fcn`。随后，对 $n$ 从 $0$ 到 $100$ 的每个值计算部分和，并将结果存储在列表`seq_sum_array`中。这个部分和的计算过程用于观察数列在不同$n$值下的累积增长趋势。\n",
    "\n",
    "4. **绘制部分和的收敛趋势图**：使用`Matplotlib`绘制部分和的离散点图。横轴为 $n$ 的对数刻度，以便更清晰地展示数列在大$n$下的增长或收敛情况。纵轴表示部分和的值，通过观察其上限（设为 $3$），可以直观地判断部分和的收敛特性。\n",
    "\n",
    "最终，代码生成的图像展示了数列的部分和在不同 $n$ 下的变化规律，帮助分析这些数列的收敛性。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb55ce69-66d8-4ae9-b692-d7e082a3802b",
   "metadata": {},
   "source": [
    "## 导入包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bc7915fc-7abb-4040-bd22-a6cd39d4259c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import limit_seq, Sum, lambdify, factorial  # 导入SymPy中求极限、求和、符号化函数和阶乘的函数\n",
    "from sympy.abc import n, k  # 导入符号变量n和k\n",
    "import numpy as np\n",
    "from matplotlib import pyplot as plt  # 导入NumPy和Matplotlib用于数值计算和绘图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "014c1571-66bc-4c75-b543-b886151577bf",
   "metadata": {},
   "source": [
    "## 定义数列的部分和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "880bd764-ba06-41ff-a361-ac7ba7076da8",
   "metadata": {},
   "outputs": [],
   "source": [
    "seq_sum = Sum(1 / 2**k, (k, 0, n))  # 定义数列的部分和: 1/(2^k)从k=0到n的和\n",
    "seq_sum = Sum(1 / ((k + 1)*(k + 2)), (k, 0, n))  # 定义数列的部分和: 1/((k+1)*(k+2))从k=0到n的和\n",
    "seq_sum = Sum(1 / factorial(k), (k, 0, n))  # 定义数列的部分和: 1/k!从k=0到n的和"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46f404ac-1ae6-45f6-9256-22bff7e4c2a0",
   "metadata": {},
   "source": [
    "## 求数列的极限"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1e82007e-ec63-4542-8efd-7ce2718e5c3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "seq_limit = limit_seq(seq_sum, n)  # 计算数列和的极限，当n趋近于无穷大时的值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbe2c991-8f92-4ab8-964f-b559bcd3c95c",
   "metadata": {},
   "source": [
    "## 转换为可数值计算的函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4c5f3d87-2fd6-4a1d-8865-ebf95e140c86",
   "metadata": {},
   "outputs": [],
   "source": [
    "seq_sum_fcn = lambdify(n, seq_sum)  # 将数列部分和表达式转换为可以数值计算的函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a93b5c08-681e-4945-9b23-ecc67df68856",
   "metadata": {},
   "source": [
    "## 计算数列部分和在n=5时的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dc681728-5ed6-46eb-8657-cda86cacd173",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 2.71666666666667$"
      ],
      "text/plain": [
       "2.71666666666667"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "seq_sum.evalf(subs={n: 5})  # 求部分和在n=5时的数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec5d6996-7e62-4d42-b371-4ed113a5d98e",
   "metadata": {},
   "source": [
    "## 初始化数列项的范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9f591134-3e19-4f25-aaa9-0a4f4828640b",
   "metadata": {},
   "outputs": [],
   "source": [
    "n_array = np.arange(0, 100 + 1, 1)  # 定义n的取值范围，从0到100，每次增加1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3202e849-0203-46cd-a45d-4ebcb96e2b58",
   "metadata": {},
   "source": [
    "## 计算部分和的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4aad6272-bef9-4650-a1b6-ec7ac25472b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "seq_sum_array = []  # 创建列表用于存储数列部分和\n",
    "\n",
    "for n in n_array:\n",
    "    seq_n = seq_sum_fcn(n)  # 计算部分和的第n项\n",
    "    seq_sum_array.append(seq_n)  # 将部分和的第n项添加到列表中"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad5a786d-a433-4a58-95c6-cd56d23dec43",
   "metadata": {},
   "source": [
    "## 绘制数列部分和的图像"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "362cae5f-38eb-495b-8252-309eea176ce4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAnYAAAHWCAYAAAD6oMSKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAutklEQVR4nO3de3BUZZ7G8acJuSHQyCUhSICoTIRwNcQhUW6CAVKDo2AttTWFTg3Mmh2VlUgxBHdq1XUnTMk4iBdYHBGRVaMTRWeISMZJAkK8BBJARBSNhmU7xoAmGiAX0vsHQ49Nbn063TnJy/dTdYqc97zve37d1AkP59LtcLvdbgEAAKDb62F3AQAAAAgMgh0AAIAhCHYAAACGINgBAAAYgmAHAABgCIIdAACAIQh2AAAAhiDYAQAAGIJgBwAAYAiCHQAAgCFsDXbr16/XuHHj1LdvX/Xt21fJycl688032xxTWFioxMRERURE6Morr9SGDRs6qVoAAICuzdZgN3ToUK1evVrFxcUqLi7WjTfeqJ/+9Kc6fPhwi/3LysqUlpamKVOmqKSkRKtWrdLSpUuVk5PTyZUDAAB0PQ632+22u4gf6t+/vx555BEtXry42bZf//rXeuONN3TkyBFPW3p6ug4cOKCioqLOLBMAAKDL6TL32J07d04vvfSSamtrlZyc3GKfoqIipaamerXNnj1bxcXFamhoaHFMXV2dampqPEt1dbW+/vprdbE8CwAA0GG2B7tDhw6pd+/eCg8PV3p6ul577TWNHj26xb4VFRWKjo72aouOjlZjY6OqqqpaHJOVlSWn0+lZ+vXrp6ioKL300kuthsGWNDQ06PXXX/d5jNX+l7ru+H7ZXXOw9x/o+QMxX0fm8Gcsx31wdcf3y+6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di3W63mpqaJEl//etf9ZOf/ESSFBsbq6qqKktzff/99zp27JhnvaysTKWlperfv7+GDRumzMxMnThxQlu2bJEkrV27ViNGjFBCQoLq6+u1detW5eTk2BIoAQAAuhrLwW7SpEl6+OGHNWvWLBUWFmr9+vWSzoey6OhoS3MVFxdrxowZnvUL98Ldcccd2rx5s1wul+e7aCWpvr5ey5cv14kTJxQZGamEhARt375daWlpVl8GAACAcSwHu7Vr1+pnP/uZtm3bpvvvv19XX321JOlPf/qTUlJSLM01ffp0ud3uVrdv3rzZa33FihW23McHAADQHVgOduPGjdOhQ4eatT/yyCMKCQkJSFEAAACwzq/PsWtJREREoKYCAACAHyw/FQsAAICuiWAHAABgCJ+CHd+vCgAA0PX5FOwuv/xyVVZWSpJuvPFGffvtt8GsCQAAAH7wKdj17t1bJ0+elCQVFBSooaEhqEUBAADAOp+eip01a5ZmzJihUaNGSZJuvfVWhYWFtdj3b3/7W+CqAwAAgM98CnZbt27Vc889p88++0yFhYVKSEhQr169gl0bAAAALPAp2EVGRio9PV3S+a8B+93vfqd+/foFsy4AAABYZPkDivPz8z0/X/g6MIfDEbiKAAAA4Be/Psduy5YtGjt2rCIjIxUZGalx48bp+eefD3RtAAAAsMDyGbtHH31Uv/nNb3T33Xfr+uuvl9vt1p49e5Senq6qqiotW7YsGHUCAACgHZaD3eOPP67169fr9ttv97T99Kc/VUJCgh544AGCHQAAgE0sX4p1uVxKSUlp1p6SkiKXyxWQogAAAGCd5WB39dVX6+WXX27Wnp2drZEjRwakKAAAAFhn+VLsgw8+qIULF2rXrl26/vrr5XA49M477+jtt99uMfABAACgc1g+Y7dgwQK99957GjhwoLZt26ZXX31VAwcO1Pvvv69bb701GDUCAADAB5bP2ElSYmKitm7dGuhaAAAA0AF+fY4dAAAAuh6CHQAAgCEIdgAAAIYg2AEAABiCYAcAAGAIy0/Fnj17Vo8//rjy8/NVWVmppqYmr+379+8PWHEAAADwneVg94tf/EJ5eXm67bbbdN1118nhcASjLgAAAFhkOdht375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ampk6viUuxATRw4ECFhIR4/S9dkiorK5ulegBm4LgHLj1d+bgn2AVQWFiYEhMTlZeX59Wel5enlJQUm6oCEEwc98Clpysf91yKtej777/XsWPHPOtlZWUqLS1V//79NWzYMGVkZGjRokWaNGmSkpOTtXHjRpWXlys9Pd3GqgF0BMc9cOnptsd9pz1/a4j8/Hy3pGbLHXfc4enz5JNPuocPH+4OCwtzX3vtte7CwkL7CgbQYRz3wKWnux73fFcsAACAIbjHDgAAwBAEOwAAAEMQ7AAAAAxBsAMAADAEwQ4AAMAQBDsAAABDEOwAAAAMQbADAAAwBMEOAADAEAQ7AAAAQxDsAKCD7rvvPs2bN8/uMgCAYAcAHVVaWqoJEybYXQYAEOwAoKMOHDigiRMn2l0GABDsAKAjjh8/rpMnT3rO2H377beaN2+eUlJS5HK57C0OwCWHYAcAHVBaWiqn06m4uDgdOnRISUlJiomJUUFBgWJiYuwuD8AlhmAHAB1QWlqq8ePH68UXX9TUqVO1fPlybdy4UWFhYXaXBuAS5HC73W67iwCA7mrBggXKz8+XJP3lL39RSkqKzRUBuJRxxg4AOqC0tFQLFizQ2bNn9e2339pdDoBLHGfsAMBP3333nZxOp/bt26cDBw7o3/7t37R3714lJCTYXRqAS1RPuwsAgO6qtLRUISEhGj16tCZOnKjDhw9r3rx5ev/99zVw4EC7ywNwCeJSLAD46cCBA7rmmmsUHh4uSfrd736n0aNHa/78+aqvr7e5OgCXIi7FAgAAGIIzdgAAAIYg2AEAABiCYAcAAGAIgh0AAIAhCHYAAACGINgBAAAYgmAHAABgCIIdAACAIQh2AAAAhiDYAQAAGIJgBwAAYAiCHQAAgCH+HwvnkPft8cZMAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots()  # 创建绘图窗口\n",
    "\n",
    "ax.plot(n_array, seq_sum_array, linestyle='None', marker='.')  # 绘制部分和的离散点图\n",
    "\n",
    "ax.set_xlabel('$k$')  # 设置x轴标签\n",
    "ax.set_ylabel('Sum of sequence')  # 设置y轴标签\n",
    "ax.set_xscale('log')  # 将x轴的刻度设置为对数刻度\n",
    "ax.set_ylim(0, 3)  # 设置y轴的范围\n",
    "ax.spines['right'].set_visible(False)  # 隐藏右边框\n",
    "ax.spines['top'].set_visible(False)  # 隐藏上边框\n",
    "plt.grid(True, which=\"both\", axis='x')  # 在x轴方向上设置网格线，对数刻度下所有刻度都有网格\n",
    "plt.tight_layout()  # 紧凑布局\n",
    "plt.show()  # 显示绘图结果"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
